<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

mysql_connect("localhost","infopark_com_ua","8888zG6Wtv1k");
mysql_select_db("pro_infopark_com_ua");

$pre_path='/var/www/infopark_com_ua/data/www/pro.infopark.com.ua/sites/default/files/';
 $folders_list=glob("/var/www/infopark_com_ua/data/www/pro.infopark.com.ua/sites/default/files/styles/*");
 function find_files($path)
 {
      $files=glob($path);
     for($i=0;$i<count($files);$i++)
     {
        # print $files[$i]."<hr>";
         if(is_dir($files[$i]))
         {
         $files=array_merge($files,find_files($files[$i]."/*"));
         unset($files[$i]);
         
         }
         
     }
     sort($files);
     return $files;
 }
 print "<pre>";
 $c=0;
 foreach($folders_list as $folder)
 {
     $files=find_files($folder."/*");
    #print_r($files);
     foreach($files as $file)
     {
         if(!is_dir($file))
         {    
         $filo=substr($file,81);
         $filo=substr($filo,strpos($filo,"/"));
         $filo=substr($filo,strpos($filo,"/",1)+1);
               
         if(!file_exists($pre_path.$filo))
         {  
             unlink($file);
             print $file." deleted\n";
             $c++;
         }
         }
         //print substr($file,0,309)."\n";
     }
     
   
 }
 print "Total deleted ".$c." files\n";
 print "</pre>";
?>
